package com.example.springmvcdemo3;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @author Q
 * @create 2025-05-25-17:32
 */
@RequestMapping("/response")
@Controller
@ResponseBody
public class ResponseController {
    //返回视图
    @ResponseBody
    @RequestMapping("/index")
    public String index() {
        return "/index.html";
    }
    //返回数据
    @ResponseBody
    @RequestMapping("/returnDate")
    public String returnDate() {
        return "返回数据";
    }
    //返回HTML代码块
    @RequestMapping("/returnHTML")
    @ResponseBody
    public String returnHTML() {
        return "<h1>返回HTML代码块</h1>";
    }
    @RequestMapping("/returnJson")
    public HashMap<String, String> returnJson() {
        HashMap<String, String> map = new HashMap<>();
        map.put("Java", "Java Value");
        map.put("MySQL", "MySQL Value");
        map.put("Redis", "Redis Value");
        return map;
    }
    @RequestMapping(value = "/setStatus")
    @ResponseBody
    public String setStatus(HttpServletResponse response) {
        response.setStatus(401);
        return "设置状态码成功";
    }
}
